package sword.T63;

/**
 * @Author: 18362
 * @Create: 2022-04-10 18:53:28 星期日
 */

class Solution {
    public int maxProfit(int[] prices) {
        int dp0 = 0, dp1 = Integer.MIN_VALUE;
        for(int i=0; i<prices.length; ++i) {
            dp0 = Math.max(dp0, dp1+prices[i]);
            dp1 = Math.max(dp1, -prices[i]);
        }
        return dp0;
    }
}